'use strict';
app.controller('regionalPortraitCtrl', ['$scope', 'toaster', 'utilService', function ($scope, toaster, utilService) {
    $scope.ecOption=[
        {name: '北京', value: Math.round(Math.random() * 1000)},
        {name: '天津', value: Math.round(Math.random() * 1000)},
        {name: '上海', value: Math.round(Math.random() * 1000)},
        {name: '重庆', value: Math.round(Math.random() * 1000)},
        {name: '河北', value: Math.round(Math.random() * 1000)},
        {name: '河南', value: Math.round(Math.random() * 1000)},
        {name: '云南', value: Math.round(Math.random() * 1000)},
        {name: '辽宁', value: Math.round(Math.random() * 1000)},
        {name: '黑龙江', value: Math.round(Math.random() * 1000)},
        {name: '湖南', value: Math.round(Math.random() * 1000)},
        {name: '安徽', value: Math.round(Math.random() * 1000)},
        {name: '山东', value: Math.round(Math.random() * 1000)},
        {name: '新疆', value: Math.round(Math.random() * 1000)},
        {name: '江苏', value: Math.round(Math.random() * 1000)},
        {name: '浙江', value: Math.round(Math.random() * 1000)},
        {name: '江西', value: Math.round(Math.random() * 1000)},
        {name: '湖北', value: Math.round(Math.random() * 1000)},
        {name: '广西', value: Math.round(Math.random() * 1000)},
        {name: '甘肃', value: Math.round(Math.random() * 1000)},
        {name: '山西', value: Math.round(Math.random() * 1000)},
        {name: '内蒙古',value: Math.round(Math.random()*1000)},
        {name: '陕西', value: Math.round(Math.random() * 1000)},
        {name: '吉林', value: Math.round(Math.random() * 1000)},
        {name: '福建', value: Math.round(Math.random() * 1000)},
        {name: '贵州', value: Math.round(Math.random() * 1000)},
        {name: '广东', value: Math.round(Math.random() * 1000)},
        {name: '青海',value: Math.round(Math.random()*1000)},
        {name: '西藏', value: Math.round(Math.random() * 1000)},
        {name: '四川', value: Math.round(Math.random() * 1000)},
        {name: '宁夏', value: Math.round(Math.random() * 1000)},
        {name: '海南', value: Math.round(Math.random() * 1000)},
        {name: '台湾', value: Math.round(Math.random() * 1000)},
        {name: '香港', value: Math.round(Math.random() * 1000)},
        {name: '澳门', value: Math.round(Math.random() * 1000)}
    ]
}]);
app.directive('echartsMap', ['$timeout', function ($timeout) {
    return {
        restrict: 'E',
        replace: true,
        scope: {
            ecOption: '='     //这里的作用是数据绑定
        },
        template: '<div style="height:800px;width:100%" id="main"></div>',   // 自定义图表宽高
        link:function($scope,element,attrs,controller){
            var itemStyle = {
                normal: {
                    borderColor: 'rgba(0, 0, 0, 0.2)'
                },
                emphasis: {
                    shadowOffsetX: 0,
                    shadowOffsetY: 0,
                    shadowBlur: 20,
                    borderWidth: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            };
            var option={
                title: {
                    text: '中国地图',
                    subtext: '纯属虚构',
                    left: 'center'
                },
                legend: {
                    orient: 'vertical',
                    left: 'left',
                    data: ['myData']
                },
                visualMap: {
                    seriesIndex: 0,
                    min: 0,
                    max: 1000,
                    left: 'left',
                    top: 'bottom',
                    text: ['高', '低'],           // 文本，默认为数值文本
                    calculable: true
                    //inRange: {
                    //    // color: ['#3B5077', '#031525'] // 蓝黑
                    //    // color: ['#ffc0cb', '#800080'] // 红紫
                    //    // color: ['#3C3B3F', '#605C3C'] // 黑绿
                    //    // color: ['#0f0c29', '#302b63', '#24243e'] // 黑紫黑
                    //    // color: ['#23074d', '#cc5333'] // 紫红
                    //    color: ['#00467F', '#A5CC82'] // 蓝绿
                    //    // color: ['#1488CC', '#2B32B2'] // 浅蓝
                    //    // color: ['#00467F', '#A5CC82'] // 蓝绿
                    //    // color: ['#00467F', '#A5CC82'] // 蓝绿
                    //    // color: ['#00467F', '#A5CC82'] // 蓝绿
                    //    // color: ['#00467F', '#A5CC82'] // 蓝绿
                    //
                    //}
                },
                selectedMode: 'single',
                tooltip: {},
                series: [{
                    name: 'myData',
                    type: 'map',
                    map: 'china',
                    itemStyle: itemStyle,
                    showLegendSymbol: true,
                    //zoom: 10,
                    //center: [115.97, 29.71],
                    roam: true,
                    //markPoint: {
                    //    data: [{
                    //        coord: [115.97, 29.71]
                    //    }]
                    //},
                    label: {
                        normal: {
                            show: true,
                            //rotate: 40,
                            //formatter: '{b}：{value|{c}}',
                            //// position: 'inside',
                            //backgroundColor: '#fff',
                            //padding: [3, 5],
                            //borderRadius: 3,
                            //borderWidth: 1,
                            //borderColor: 'rgba(0,0,0,0.5)',
                            //color: '#777',
                            //rich: {
                            //    value: {
                            //        color: '#019D2D',
                            //        fontSize: 14,
                            //        // fontWeight: 'bold'
                            //        // textBorderWidth: 2,
                            //        // textBorderColor: '#000'
                            //    }
                            //}
                        },
                        emphasis: {
                            show: true
                        }
                    },
                    data:$scope.ecOption
                }]
            }
            $.getJSON('vendor/jquery/echarts-2.2.7/build/source/chart/china.json', function (chinaJson) {
                echarts.registerMap('china', chinaJson);
                var chart = echarts.init(document.getElementById('main'));
                chart.setOption(option);
            });
        }
    };
}])